app.controller("examinationController",function($scope, $http){
             $http({
                method: 'GET',
                url: 'home/examination/test.json'
            }).success(function (response) {
                console.log(response)               //总条数
                $scope.total = response.total;
                //反转函数转化abcd转dcba
                $scope.data = response.data.reverse();
                //选择显示的条数
                $scope.values = [{"limit":6}];
                //默认显示的条数
                $scope.selectedLimit=$scope.values[0];
                //默认显示当前页数
                $scope.currentPage = 1;
                if($scope.data != null){
                    $scope.datas = $scope.data.slice($scope.selectedLimit.limit*($scope.currentPage-1),$scope.selectedLimit.limit*$scope.currentPage);
                }else{
                    alert($scope.data);
                }
                $scope.page = {
                "limit":$scope.selectedLimit.limit,"pageSize":5,"pageNo":$scope.currentPage,"totalCount":$scope.total};
                // 2017 /7 /19
                // 定义一个空对象 , 用于更新和保存数据时临时存储
                $scope.prod = {};
                $scope.arrs=response.data;
                console.log($scope.arrs)
                // 定义一个单击删除按钮时触发的事件，用于删除选中行
                 $scope.delete = function($index){
                    if ($index>=0) {
                        if(confirm("是否删除"+$scope.arrs[$index].name+"的排课么") ){
                        $scope.arrs.splice($index,1);
                        //将需要删除的卡号传给后台  2017/7/10
                        $http.post('recruit/Daily/test.json',{number:$scope.arrs[$index].number})
                        .success(function (result) {
                          if (result.success) {
                                alert(result.success)
                             }
                        }).error(function(result){
                                alert(result.error)
                          })
                        }
                    };
                }  
              // 2017 7/11 
                // 发布功能 guohongjun
                $scope.applyUp =function($index){
                    if ($index>=0) {
                        if (confirm("是否发布"+$scope.arrs[$index].name+"的课程")) {
                            $http.post('recruit/Daily/test.json',{number:$scope.arrs[$index].id}).then(function(project){
                                   alert(project.success)
                            })                                  
                        };
                    };
                }
               //定义一个全局变量idx  , 用于存储选中行的索引，方便执行保存操作时保存数据  
               var  idx=-1
               $scope.updata =function ($index){
               //显示bootstrap中的模块窗口
                $('#modalModify').modal('show');
               //将选中行的数据绑定到临时对象prod中，在下面的模态窗口中展示出来
                $scope.prod.order = $scope.arrs[$index].order;
                $scope.prod.number = $scope.arrs[$index].number;  //学号
                $scope.prod.card = $scope.arrs[$index].card;      //卡号
                $scope.prod.school = $scope.arrs[$index].school;  // 学校
                $scope.prod.type = $scope.arrs[$index].type;      //类别
                $scope.prod.people = $scope.arrs[$index].people;  //负责人
                $scope.prod.name = $scope.arrs[$index].name;      //姓名
                $scope.prod.date = $scope.arrs[$index].date;      //日期 
                $scope.prod.job =$scope.arrs[$index].job;  //职务    
                idx = $index;           
               };
               $scope.save =function (){
                //将修改后的值赋给数组
                $scope.arrs[idx].order = $scope.prod.order;
                $scope.arrs[idx].number = $scope.prod.number;
                $scope.arrs[idx].card = $scope.prod.card;
                $scope.arrs[idx].order = $scope.prod.order;
                $scope.arrs[idx].school = $scope.prod.school;
                $scope.arrs[idx].type = $scope.prod.type;                
                $scope.arrs[idx].people = $scope.prod.people;
                $scope.arrs[idx].name = $scope.prod.name;
                $scope.arrs[idx].date = $scope.prod.date;
                $scope.arrs[idx].job =$scope.prod.job;
                // 2017/7/19  保存后发送数据到后台修改数据库
                //Create guohongjun
               $http.post('recruit/transfer/test.json',{order:$scope.prod.order,number:$scope.prod.number,card:$scope.prod.card,school:$scope.prod.school,type:$scope.prod.type,people:$scope.prod.people,name:$scope.prod.name,date:$scope.prod.date,job:$scope.prod.job})
               .success(function (response){
                     if (response.success) {
                      alert(response.success)
                     };  
               }).error (function (response){
                      alert(response.error)
               })
                   $('#modalModify').modal('hide');        
               } 
            })
            $scope.change = function(selectedLimit){
                $scope.page.limit = selectedLimit.limit;
                $scope.datas = $scope.data.slice($scope.selectedLimit.limit*($scope.page.pageNo-1),$scope.selectedLimit.limit*$scope.page.pageNo);
            }
            $scope.pageChanged = function(){
                $scope.page.limit = $scope.selectedLimit.limit;
                $scope.datas = $scope.data.slice($scope.selectedLimit.limit*($scope.page.pageNo-1),$scope.selectedLimit.limit*$scope.page.pageNo);
            }
            $scope.setPage = function (go) {
                $scope.length = Math.ceil($scope.total/$scope.selectedLimit.limit);
                console.log($scope.length);
                if(go > $scope.length){
                    $scope.page.pageNo =  $scope.length;
                    console.log($scope.length);
                    
                }else{
                    $scope.page.pageNo=go; 
                }
                $scope.datas = $scope.data.slice($scope.selectedLimit.limit*($scope.page.pageNo-1),$scope.selectedLimit.limit*$scope.page.pageNo);
            };
            // 一对一表单事件准备工作
            // 2017 / 7 / 16
            // guohongjun
                     $scope.schoolUserName;  //姓名
                     $scope.userSchool;  //学校
                     $scope.userSex //性别
                     $scope.mobilePhone //手机
                     $scope.weChat  //微信
                     $scope.modeltime; //报名日期
                     $scope.cardNumber  //卡号
                     $scope.classHours  //课时
                     $scope.unitPrice  //原单价 
                     $scope.note //优惠备注
                     $scope.discountAmount; //优惠金额  
                     $scope.parentsStudent  //学生家长  
                     $scope.tutionFree = Number($scope.classHours)*Number($scope.unitPrice)//学费
                     $scope.totalPrice = Number($scope.tutionFree) - Number($scope.discountAmount) //实际总金额
                     $scope.nowPrice =(Number($scope.tutionFree) - Number($scope.discountAmount))/$scope.classHours//现有单价
                 var  duty=$('#duty').find('option:selected').text(); //职务类别                                                                             
                 var  shcoolGrade=$('#shcoolGrade').find('option:selected').text(); //年级    
                 var  toOneSchool=$('#toOneSchool').find('option:selected').text(); //校区                        
                 var  ApplicationType=$('#ApplicationType').find('option:selected').text(); //申请类型 
                 var  PaymentMethods=$('#PaymentMethods').find('option:selected').text(); //缴费类型 
                 var  teacherLevel=$('#teacherLevel').find('option:selected').text(); //缴费类型   
                 var  headPeople=$('#headPeople').find('option:selected').text(); //负责人 
                 var  headMaster=$('#headMaster').find('option:selected').text(); //校长                                      
            $scope.oneToOne= function(){
                  tutionFree=$('#tutionFree').val();
                  nowPrice=$('#nowPrice').val();
                  totalPrice=$('#totalPrice').val();
                  var  modeltime=angular.element(document.querySelector('#modeltime')).val();
                  oneToOneTime = modeltime.replace(/-/g,'/'); // 将-替换成/，因为下面这个构造函数只支持/分隔的日期字符串
                  var classOneToOne = new Date(oneToOneTime).getTime(); // 构造一个日期型数据，值为传入的字符串  
                  console.log(classOneToOne)               
                  $http.post('recruit/Daily/test.json',{schoolUserName:$scope.schoolUserName,
                                                        userSchool:$scope.userSchool,
                                                        userSex:$scope.userSex,
                                                        mobilePhone:$scope.mobilePhone,
                                                        weChat:$scope.weChat,
                                                        modeltime:$scope.modeltime,
                                                        cardNumber:$scope.cardNumber,
                                                        classHours:$scope.classHours,
                                                        unitPrice:$scope.unitPrice,
                                                        note:$scope.note,
                                                        discountAmount:$scope.discountAmount,
                                                        parentsStudent:$scope.parentsStudent,
                                                        duty:duty,
                                                        shcoolGrade:shcoolGrade,
                                                        toOneSchool:toOneSchool,
                                                        ApplicationType:ApplicationType,
                                                        PaymentMethods:PaymentMethods,
                                                        teacherLevel:teacherLevel,
                                                        headPeople:headPeople,
                                                        headMaster:headMaster,
                                                        tutionFree:tutionFree,
                                                        nowPrice:nowPrice,
                                                        lessonDate:classOneToOne,
                                                        totalPrice:totalPrice}).success(function(result){
                                                            if (result.result==1){
                                                                   alert(result.success) 
                                                                   $scope.data = result.data.reverse();
                                                            }else if(result.result==0){
                                                                   alert(result.error)
                                                            }

                                                        })
                                                       }
                // 2017 7 / 16
                // 班课准备工作
                // Create guohongjun
                      $scope.classUserName  // 姓名
                      $scope.classSchool  //学校
                      $scope.userClassSex //性别
                      $scope.classTelephone //手机
                      $scope.weDress //微信
                      $scope.classSubject //科目
                      $scope.classCardNumber //卡号
                      $scope.originalPrice  //原单价
                      $scope.classNumber  //课时 
                      $scope.classRoomBoard //食宿费 
                      $scope.classNote //备注
                      $scope.classPeferential   //优惠金额  
                      $scope.classParents //学生家长                                       
                 var  classGrade=$('#classGrade').find('option:selected').text(); //年级      
                 var  classCost=$('#classCost').find('option:selected').text(); //缴费方式
                 var  classSprint=$('#classSprint').find('option:selected').text(); //班级                     
                 var  classSchoolObj=$('#classSchoolObj').find('option:selected').text(); //校区    
                 var  Classification=$('#Classification').find('option:selected').text();  //申请类型
                 var  classJobCategory=$('#classJobCategory').find('option:selected').text(); //,职务类别
                 var  fuzePeople=$('#fuzePeople').find('option:selected').text(); //负责人
                 var  classSchoolPeople=$('#classSchoolPeople').find('option:selected').text(); //校长                 
                      $scope.classTuitionFees = Number($scope.originalPrice)* Number($scope.classNumber)//学费
                      $scope.nowPayment =Number($scope.classTuitionFees) - Number($scope.classPeferential)//实际总缴费
                      $scope.classNowPrice = Number($scope.nowPayment)/Number($scope.classNumber)//现有单价
                  $scope.classClass=function(){
                      classTuitionFees=$("#classTuitionFees").val();
                      console.log(classTuitionFees)
                      classNowPrice=$("#classNowPrice").val();
                      nowPayment=$("#nowPayment").val();
                  var  modeltimetwo=angular.element(document.querySelector('#modeltimetwo')).val();
                  classTime = modeltimetwo.replace(/-/g,'/'); // 将-替换成/，因为下面这个构造函数只支持/分隔的日期字符串
                  var classTimeUnix = new Date(classTime).getTime(); // 构造一个日期型数据，值为传入的字符串  
                  console.log(classTimeUnix);
                  $http.post('recruit/Daily/test.json',{classUserName:$scope.classUserName,
                                                        classSchool:$scope.classSchool,
                                                        userClassSex:$scope.userClassSex,
                                                        classTelephone:$scope.classTelephone,
                                                        weDress:$scope.weDress,
                                                        classSubject:$scope.classSubject,
                                                        classCardNumber:$scope.classCardNumber,
                                                        originalPrice:$scope.originalPrice,
                                                        classNumber:$scope.classNumber,
                                                        classRoomBoard:$scope.classRoomBoard,
                                                        classNote:$scope.classNote,
                                                        classPeferential:$scope.classPeferential,
                                                        classParents:$scope.classParents,
                                                        classGrade:classGrade,
                                                        classCost:classCost,
                                                        classSprint:classSprint,
                                                        classSchoolObj:classSchoolObj,
                                                        Classification:Classification,
                                                        classJobCategory:classJobCategory,
                                                        fuzePeople:fuzePeople,
                                                        classSchoolPeople:classSchoolPeople,
                                                        classTuitionFees:classTuitionFees,
                                                        classNowPrice:classNowPrice,
                                                        nowPayment:nowPayment,
                                                        classTimeUnix:classTimeUnix
                                                      }).success(function(result){
                                                            if (result.result==1){
                                                                   alert(result.success) 
                                                                   $scope.data = result.data.reverse();
                                                            }else if(result.result==0){
                                                                   alert(result.error)
                                                            }

                                                        })
                                                }
        $scope.ToView=function($index){
        //将选中行的数据绑定到临时对象findview中，在下面的模态窗口中展示出来
            $('#check').modal('show');
            $http({
                 method: 'GET',
                 url: 'recruit/Daily/daily.json'     
            }).success(function (response){
                 $scope.newdata=response.data.reverse();
                 $scope.cosTiotion = $scope.newdata[$index].cosTiotion;
                 $scope.elapsedTime = $scope.newdata[$index].elapsedTime;
                 $scope.totalfees = $scope.newdata[$index].totalfees;
                 $scope.class = $scope.newdata[$index].class;       
                 $scope.subject = $scope.newdata[$index].subject;
                 $scope.originalType = $scope.newdata[$index].originalType;
                 $scope.level = $scope.newdata[$index].level;
                 $scope.card = $scope.newdata[$index].card;
                 $scope.price = $scope.newdata[$index].price;
                 $scope.classHour = $scope.newdata[$index].classHour;
                 $scope.preferential = $scope.newdata[$index].preferential;
                 $scope.classStudentName = $scope.newdata[$index].classStudentName;
                 $scope.grade = $scope.newdata[$index].grade;
                 $scope.school = $scope.newdata[$index].school;
                 $scope.orgData = $scope.newdata[$index].orgData;
                 $scope.transferData = $scope.newdata[$index].transferData;
                 $scope.payment = $scope.newdata[$index].payment;                 
            })                       
      }
     
      
    });


